﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcAtletIS.Models;

namespace MvcAtletIS.Controllers
{
    public class DocumentsController : Controller
    {
        private atletisEntities db = new atletisEntities();

        // GET: /Documents/
        public ActionResult Index(int CategoryId = 1)
        {
            if (User.IsInRole("Federation"))
            {
                ViewBag.CategoryId = new SelectList(db.DocumentsCategories.OrderBy(dc => dc.Order).ToList(), "ID", "Name", CategoryId);
            }
            else
            {
                ViewBag.CategoryId = new SelectList(db.DocumentsCategories.Where(dc => dc.Active == true).OrderBy(dc => dc.Order).ToList(), "ID", "Name", CategoryId);
            }

            ViewBag.ImportantSubcategories = db.DocumentsSubcategories.Where(ds => ds.CategoryId == CategoryId & ds.Active == true & ds.Important == true).OrderBy(ds => ds.Order).ToList();
            ViewBag.CommonSubcategories = db.DocumentsSubcategories.Where(ds => ds.CategoryId == CategoryId & ds.Active == true & ds.Important == false).OrderBy(ds => ds.Order).ToList();

            List<Documents> model = db.Documents.Include("DocumentsSubcategories").Where(d => d.DocumentsSubcategories.CategoryId == CategoryId & d.Active == true).OrderByDescending(d => d.Date).ToList();
            return View(model);
        }

    }
}
